//
//  ZYImageCache.h
//  ZYWebImage
//
//  Created by wangzhipan on 2025/3/17.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "IZYImageCacheProtocol.h"


NS_ASSUME_NONNULL_BEGIN
@class ZYImageCacheTask;
@interface ZYImageCache : NSObject
+ (instancetype)sharedImageCache;

//sync
- (void)storeImageToMemory:(UIImage *)image
                    forKey:(NSString *)key;

//sync
- (void)storeImageToDisk:(UIImage *)image
                  forKey:(NSString *)key 
                  format:(ZYImageFormat)format;

//sync
- (void)storeImageToAll:(UIImage *)image
                 forKey:(NSString *)key
                 format:(ZYImageFormat)format;

//sync
- (void)storeImageDataToDisk:(NSData *)imageData
                      forKey:(NSString *)key;

//sync
- (nullable UIImage *)imageFromDiskCacheForKey:(NSString *)key;

//sync
- (nullable UIImage *)imageFromMemoryCacheForKey:(NSString *)key;

//sync
- (nullable UIImage *)imageFromCacheForKey:(NSString *)key;

//sync
- (BOOL)diskImageDataExistsWithKey:(NSString *)key;

//sync
- (void)removeImageFromMemoryForKey:(NSString *)key;

//sync
- (void)removeImageFromDiskForKey:(NSString *)key;

//sync
- (void)removeImageFromCacheForKey:(NSString *)key;

//sync
- (nullable NSString *)cachePathForKey:(NSString *)key;



//async
- (void)storeImage:(UIImage *)image
            forKey:(NSString *)key
              type:(ZYImageCacheType)type
            format:(ZYImageFormat)format
         completed:(nullable dispatch_block_t)completed;

//async
- (void)storeImageData:(NSData *)imageData
                forKey:(NSString *)key
             completed:(nullable dispatch_block_t)completed;

//async
- (ZYImageCacheTask *)queryCacheTaskForKey:(NSString *)key
                                      type:(ZYImageCacheType)type
                                 completed:(nullable ZYImageCacheQueryCompletionBlock)completed;
//async
- (void)removeImageForKey:(NSString *)key
                     type:(ZYImageCacheType)type
                completed:(nullable dispatch_block_t)completed;

/**
 * Synchronously Clear all memory cached images
 */
- (void)clearMemory;

/**
 * Asynchronously clear all disk cached images. Non-blocking method - returns immediately.
 * @param completion    A block that should be executed after cache expiration completes (optional)
 */
- (void)clearDiskOnCompletion:(nullable dispatch_block_t)completion;

/**
 * Asynchronously remove all expired cached image from disk. Non-blocking method - returns immediately.
 * @param completion A block that should be executed after cache expiration completes (optional)
 */
- (void)deleteOldFilesWithCompletionBlock:(nullable dispatch_block_t)completion;

/**
 * Get the total bytes size of images in the disk cache
 */
- (NSUInteger)totalDiskSize;

/**
 * Get the number of images in the disk cache
 */
- (NSUInteger)totalDiskCount;
@end

NS_ASSUME_NONNULL_END
